package com.mindcoord.handbook.service.impl;

import com.mindcoord.handbook.common.Result;
import com.mindcoord.handbook.dao.MajorMapper;
import com.mindcoord.handbook.pojo.Major;
import com.mindcoord.handbook.service.MajorService;

public class MajorServiceImpl implements MajorService {

    private MajorMapper majorMapper;

    public void setMajorMapper(MajorMapper majorMapper) {
        this.majorMapper = majorMapper;
    }

    @Override
    public Result listMajors() {
        Result result;
        try {
            result = Result.success(majorMapper.listMajors());
        } catch (Exception e) {
            result = Result.fail("查询失败");
        }
        return result;
    }

    @Override
    public Result getMajorById(Integer id) {
        Result result;
        try {
            result = Result.success(majorMapper.getMajorById(id));
        } catch (Exception e) {
            result = Result.fail("查询失败");
        }
        return result;
    }

    @Override
    public Result insertMajor(Major major) {
        Result result;
        try {
            Boolean b = majorMapper.insertMajor(major);
            result = b ? Result.success(null) : Result.fail("插入失败");
        } catch (Exception e) {
            result = Result.fail("插入失败");
        }
        return result;
    }

    @Override
    public Result deleteMajorById(Integer id) {
        Result result;
        try {
            Boolean b = majorMapper.deleteMajorById(id);
            result = b ? Result.success(null) : Result.fail("删除失败");
        } catch (Exception e) {
            result = Result.fail("删除失败");
        }
        return result;
    }

    @Override
    public Result updateMajor(Major major) {
        Result result;
        try {
            Boolean b = majorMapper.updateMajor(major);
            result = b ? Result.success(null) : Result.fail("更新失败");
        } catch (Exception e) {
            result = Result.fail("更新失败");
        }
        return result;
    }

}
